# Maintainer: George Rawlinson <grawlinson@archlinux.org>

pkgname=ruby-benchmark-ips
_pkgname="${pkgname#ruby-}"
pkgver=2.12.0
pkgrel=1
pkgdesc='Provides iteration per second benchmarking for Ruby'
arch=('any')
url='https://github.com/evanphx/benchmark-ips'
license=('MIT')
depends=('ruby')
makedepends=(
  'git'
  'ruby-rake'
  'ruby-rdoc'
)
checkdepends=('ruby-minitest')
options=('!emptydirs')
_commit='fb95c7c90a2a64171ed7ee952f0ad1b8fcfbf0e7'
source=("$pkgname::git+$url#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgname"

  git describe --tags | sed 's/^v//'
}

prepare() {
  cd "$pkgname"

  # we do not do version pinning
  sed --regexp-extended 's/~>/>=/g' --in-place *.gemspec Gemfile Rakefile
}

build() {
  cd "$pkgname"

  gem build "$_pkgname.gemspec"
}

check() {
  cd "$pkgname"

  rake
}

package() {
  cd "$pkgname"

  local _gemdir="$(gem env gemdir)"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "$pkgdir/$_gemdir" \
    --bindir "$pkgdir/usr/bin" \
    "$_pkgname-$pkgver.gem"

  # delete cache
  rm -rf "$pkgdir/$_gemdir/cache"

  # license
  install -vd "$pkgdir/usr/share/licenses/$pkgname"
  ln -sf "$_gemdir/gems/$_pkgname-$pkgver/LICENSE" "$pkgdir/usr/share/licenses/$pkgname"
}
